package com.xcj.springai.node;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.action.NodeAction;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;



@Slf4j
public class SummaryNode implements NodeAction {

    private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SummaryNode.class);

    @Override
    public Map<String, Object> apply(OverAllState state) {
        logger.info("summary node is running.");

        List<?> rawList = state.value("expander_content", List.class).orElse(List.of());
        List<String> expanderContent = rawList.stream()
                .map(Object::toString)
                .collect(Collectors.toList());

        String summary = expanderContent.stream()
                .collect(Collectors.joining("，"));

        logger.info("summary generated: {}", summary);

        return Map.of("summary_content", summary);
    }

}

